//
// Created by zhou on 2021/11/27.
//
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        int size=nums.size();
        if(size==1) return;
        bool a=false;
        for(int j=size-2;j>=0;j--) {
            for (int i = size-1; i >j; i--) {
                if (nums[j] < nums[i]) {
                    swap(nums[i], nums[j]);
                    sort(nums.begin() + j + 1, nums.end());
                    a = true;
                    break;
                }
            }
            if(a==true)break;
        }
        if(a== false){
            sort(nums.begin(),nums.end());
        }
        return ;
    }
};
int main(){
    vector<int>nums={4,2,0,2,3,2,0};
    Solution solution;
    solution.nextPermutation(nums);
    for(int i=0;i<nums.size();i++){
        cout<<nums[i]<<",";
    }
}